#include "png.h"

#include <osgDB/WriteFile>

	int toPNG(unsigned char * array, int w, int h)
	{

		osg::ref_ptr<osg::Image> image = new osg::Image(); 
		image->setImage(w, h, 1, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, array, osg::Image::NO_DELETE); 
		osgDB::writeImageFile(*image, "nombre.png"); 

		return 0;
	}

#ifdef _TEST_PNG_

#include <stdio.h>
#include <stdlib.h>
int main()
{

	int width  = 200;
	int height = 200;
	unsigned char * data = new unsigned char [width * height*4];
	//unsigned char * data = new unsigned char [width * height*3];
	int k   = 0;
 	for ( int y = 0; y<  height*width ; y +=20 )
	{
#if 0
		data [k]    = (unsigned char) 0;
		data [k +1] = (unsigned char) 0;
		data [k +2] = (unsigned char) 0;
		data [k +3] = (unsigned char) 0;
#endif
		for(int z = 0; z<10;z++){
		data [k]    = -1;
		data [k +1] = 128;
		data [k +2] = -1;
		data [k+3]  = 255;
		k+=4;
		}
		for(int z = 0; z<10;z++){
		data [k]    = 128;
		data [k +1] = -1;
		data [k +2] = -1;
		data [k+3]  = 255;
		k+=4;
		}
	}

 			

	osg::ref_ptr<osg::Image> image = new osg::Image();
	image->setImage(width, height, 1, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char*) data, osg::Image::NO_DELETE); 
	osgDB::writeImageFile(*image, "nombre.png");

	printf("FIN\n");

	return 0;
}		
#endif
